//
//  HeartBeatPacketProcess.m
//  HiQ
//
//  Created by shoguncao on 12-8-9.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "HeartBeatPacketProcess.h"
#import "MacrosDefine.h"
#import "MainWindowController.h"
#import "Connection.h"

@implementation HeartBeatPacketProcess

- (id)init
{
    isServerHeartBeatPacketReceived = YES;
    return [super init];
}

- (void)onHeartBeatTimeIntervalReach:(NSTimer *)timer
{
    if (isServerHeartBeatPacketReceived == YES)
    {
        isServerHeartBeatPacketReceived = NO;
         
        Buddy *buddy = [[MainWindowController sharedMainWindowController] myselfInfo];
        NSMutableData *sendData = [[NSMutableData alloc] init];
        [sendData appendBytes:&(buddy->buddyQQ) length:sizeof(NSInteger)];
        [[Connection sharedServerConnection] sendData:sendData cmd:CMD_FUN_HEART_BEAT subcmd:0];
    }
    else
    {
        dispatch_async(dispatch_get_main_queue(), ^{
            [[NSNotificationCenter defaultCenter] postNotificationName:OnFallLine object:nil];
        });
    }
}

- (void)onReceiveHeartBeatPacket:(NSData *)data
{
    isServerHeartBeatPacketReceived = YES;
}

@end
